<?php
/**
 * Created by PhpStorm.
 * User: boye009
 * Date: 2016/2/27
 * Time: 11:57
 */

namespace Test\Controller;

use Common\Api\BoyeServiceApi;

class TestProductController extends TestController{

    public function favorites(){
        if(IS_POST){
            $data = array(
                'product_id' => I('post.product_id',0),
                'uid' => I('uid',0),
                'favorite_value' => I('favorite_value',0),
                'api_ver' => $this->api_ver,
                'notify_id' => $this->notify_id,
                'type' => 'BY_Product_favorites',
                'alg' => 'md5',
            );
            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,true);

            $this->parseResult($result);
        }
        $this -> display();
    }

    public function getFavorites(){

        if(IS_POST){

            $data = array(
                'uid' => I('post.uid',0),
                'page_no' => I('post.page_no',1),
                'page_size' => I('post.page_size',10),
                'api_ver'=>$this->api_ver,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_Product_getFavorites',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,true);

            $this->parseResult($result);

        }

        $this->display();
    }

    public function queryFaq(){
        if(IS_POST){
            $data = array(
                'pid' => I('post.pid',0),
                'page_no' => I('post.page_no',1),
                'page_size' => I('post.page_size',10),
                'api_ver' => $this->api_ver,
                'notify_id' => $this->notify_id,
                'type' => 'BY_Product_queryFaq',
                'alg' => 'md5',
            );
            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,true);

            $this->parseResult($result);
        }
        $this -> display();
    }

    public function ask(){
        if(IS_POST){
            $data = array(
                'pid' => I('post.pid',0),
                'ask_content' => I('post.ask_content',''),
                'ask_uid' => I('post.ask_uid',0),
                'ask_username' => I('post.ask_username',''),
                'api_ver' => $this->api_ver,
                'notify_id' => $this->notify_id,
                'type' => 'BY_Product_ask',
                'alg' => 'md5',
            );
            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,true);

            $this->parseResult($result);
        }
        $this -> display();
    }

    public function detail(){

        if(IS_POST){
            $data = array(
                'id' => I('post.id',0),
                'uid' => I('post.uid',0),
                'api_ver' => $this->api_ver,
                'notify_id' => $this->notify_id,
                'type' => 'BY_Product_detail',
                'alg' => 'md5',
            );
            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,true);

            $this->parseResult($result);
        }
        $this -> display();
    }

    public function queryByGroup(){

        if(IS_POST){
            $data = array(
                'group_id'=>I('post.group_id',0),
                'cate_id'=>I('post.cate_id',0),
                'page_no'=>I('post.page_no',0),
                'page_size'=>I('post.page_size',10),
                'order'=>I('post.order',10),
                'api_ver' => $this->api_ver,
                'notify_id' => $this->notify_id,
                'type' => 'BY_Product_queryByGroup',
                'alg' => 'md5',
            );
            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,true);

            $this->parseResult($result);
        }
        $this -> display();

    }

    public function query(){

        if(IS_POST){
            $data = array(
                'cate_parent'=>I('post.cate_parent',""),
                'name'=>I('post.name',""),
                'cate_id'=>I('post.cate_id',""),
                'page_no'=>I('post.page_no',0),
                'page_size'=>I('post.page_size',10),
                'order'=>I('post.order',10),
                'min_cost'=>I('post.min_cost',""),
                'max_cost'=>I('post.max_cost',""),
                'api_ver' => $this->api_ver,
                'notify_id' => $this->notify_id,
                'type' => 'BY_Product_query',
                'alg' => 'md5',
            );
            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,true);

            $this->parseResult($result);
        }
        $this -> display();
    }

    private function parseResult($result){
        echo "解密后数据：";
        dump($result);
    }

}